home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / board / Chaos53src.lha / chaos / src / MainAmi.c < prev    next >
C/C++ Source or Header  |  1994-11-19  |  38KB  |  1,223 lines

  1. /*  Chaos:            The Chess HAppening Organisation System    V5.3
  2.     Copyright (C)   1993    Jochen Wiedmann
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.  
  19.     $RCSfile: MainAmi.c,v $
  20.     $Revision: 3.4 $
  21.     $Date: 1994/11/19 19:32:01 $
  22.  
  23.     This file contains the system dependent functions to initialize the
  24.     main window and other global stuff. Highly system dependent.
  25.  
  26.     Computer:    Amiga 1200            Compiler:    Dice 2.07.54 (3.0)
  27.  
  28.     Author:    Jochen Wiedmann
  29.         Am Eisteich 9
  30.       72555 Metzingen
  31.         Tel. 07123 / 14881
  32.         Internet: wiedmann@mailserv.zdv.uni-tuebingen.de
  33. */
  34.  
  35.  
  36. #ifndef CHAOS_H
  37. #include "chaos.h"
  38. #endif
  39.  
  40. #ifdef AMIGA
  41. #ifndef WORKBENCH_STARTUP_H
  42. #include <workbench/startup.h>
  43. #endif
  44. #ifndef LIBRARIES_GADTOOLS_H
  45. #include <libraries/gadtools.h>
  46. #endif
  47. #ifndef DOS_DOSTAGS_H
  48. #include <dos/dostags.h>
  49. #endif
  50. #ifndef CLIB_ICON_PROTOS_H
  51. #include <clib/icon_protos.h>
  52. #endif
  53.  
  54. #ifdef AZTEC_C
  55. #ifndef PRAGMAS_ICON_LIB_H
  56. #include <pragmas/icon_lib.h>
  57. #endif
  58. #endif    /*  AZTEC_C */
  59.  
  60. #if defined(_DCC)  ||  defined(__SASC)  ||  defined(__MAXON__)
  61. #ifndef PRAGMAS_ICON_PRAGMAS_H
  62. #include <pragmas/icon_pragmas.h>
  63. #endif
  64. #endif    /*  _DCC  ||  __SASC  ||  __MAXON   */
  65.  
  66. #ifdef __GNUC__
  67. #ifndef _INLINE_ICON_H
  68. #include <inline/icon.h>
  69. #endif
  70. #endif    /*  __GNUC__    */
  71.  
  72. #endif    /*  AMIGA   */
  73.  
  74.  
  75.  
  76.  
  77.  
  78. /*
  79.     CloseLibs() closes the libraries.
  80. */
  81. #ifdef AMIGA
  82. struct Library *IntuitionBase    = NULL;
  83. struct Library *MUIMasterBase    = NULL;
  84. struct Library *IFFParseBase    = NULL;
  85. struct Library *LocaleBase    = NULL;
  86. struct Library *UtilityBase    = NULL;
  87. struct Library *IconBase    = NULL;
  88. #endif    /*  AMIGA   */
  89.  
  90. void CloseLibs(void)
  91.  
  92. #ifdef AMIGA
  93. {
  94.   if (LocaleBase != NULL)
  95.   { CloseChaosCatalog();
  96.     CloseLibrary(LocaleBase);
  97.   }
  98.   if (IconBase != NULL)
  99.   { CloseLibrary(IconBase);
  100.   }
  101.   if (UtilityBase != NULL)
  102.   { CloseLibrary(UtilityBase);
  103.   }
  104.   if (IFFParseBase != NULL)
  105.   { CloseLibrary(IFFParseBase);
  106.   }
  107.   if (MUIMasterBase != NULL)
  108.   { CloseLibrary(MUIMasterBase);
  109.   }
  110.   if (IntuitionBase != NULL)
  111.   { CloseLibrary(IntuitionBase);
  112.   }
  113. }
  114. #endif    /*  AMIGA   */
  115.  
  116.  
  117. /*
  118.     DoStartup() processes the arguments (either from workbench or from
  119.     CLI). Note, that this is called before InitMain(). ShowError() probably
  120.     doesn't do its job, if it's called.
  121. */
  122. #ifdef AMIGA
  123. int MakeIcons;
  124. int NoWindow;
  125. char IconName[TRNFILENAME_LEN+1] = "s/Chaos_Project";
  126. char MenuName[TRNFILENAME_LEN+1] = "s/Chaos_Menu";
  127. char ProgName[TRNFILENAME_LEN+1];
  128. #endif    /*  AMIGA   */
  129.  
  130. void DoStartup(int argc, char *argv[])
  131.  
  132. #ifdef AMIGA
  133. { struct
  134.   { char *name;
  135.     long makeicons;
  136.     char *deficon;
  137.     char *menufile;
  138.     char *language;
  139.     long nowindow;
  140.     long *winnerpoints;
  141.     long *drawpoints;
  142.   } args;
  143.   void *key = NULL;
  144.  
  145.   args.name = NULL;
  146.   args.makeicons = (argc == 0);
  147.   args.deficon = NULL;
  148.   args.menufile = NULL;
  149.   args.language = NULL;
  150.   args.nowindow = FALSE;
  151.   args.winnerpoints = NULL;
  152.   args.drawpoints = NULL;
  153.  
  154.   if (argc == 0)  /*  Workbench-Programm  */
  155.   { struct WBStartup *WBenchMsg = (struct WBStartup *) argv;
  156.     struct WBArg *wbarg;
  157.     struct DiskObject *dobj;
  158.     char **toolarray;
  159.     char *ptr;
  160.     BPTR olddir;
  161.     int i;
  162.  
  163.     AllowErrorMessage = FALSE;
  164.     for (i = 0,  wbarg = WBenchMsg->sm_ArgList;
  165.      i < ((2 < WBenchMsg->sm_NumArgs) ? 2 : WBenchMsg->sm_NumArgs);
  166.      i++, wbarg++)
  167.     { olddir = -1;
  168.       if (wbarg->wa_Lock  &&  *wbarg->wa_Name != '\0')
  169.       { olddir = CurrentDir(wbarg->wa_Lock);
  170.       }
  171.       if (*wbarg->wa_Name != '\0'  &&
  172.       (dobj = GetDiskObject((STRPTR) wbarg->wa_Name))  !=  NULL)
  173.       { toolarray = (char **) dobj->do_ToolTypes;
  174.  
  175.     if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  176.                          (STRPTR) "NOICONS"))
  177.          !=  NULL)
  178.     { args.makeicons = FALSE;
  179.     }
  180.     if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  181.                          (STRPTR) "DEFICON"))
  182.          !=  NULL)
  183.     { args.deficon = GetStringMem(&key, ptr);
  184.       args.makeicons = TRUE;
  185.     }
  186.     if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  187.                          (STRPTR) "MENUFILE"))
  188.          !=  NULL)
  189.     { args.deficon = GetStringMem(&key, ptr);
  190.       args.makeicons = TRUE;
  191.     }
  192.     if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  193.                          (STRPTR) "LANGUAGE"))
  194.          != NULL)
  195.     { args.language = GetStringMem(&key, ptr);
  196.     }
  197.     if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  198.                      (STRPTR) "WINNERPOINTS"))
  199.          != NULL)
  200.     { DefaultWinnerPoints = atol(ptr);
  201.     }
  202.     if ((ptr = (char *) FindToolType((STRPTR *) toolarray,
  203.                      (STRPTR) "DRAWPOINTS"))
  204.          != NULL)
  205.     { DefaultDrawPoints = atol(ptr);
  206.     }
  207.  
  208.     FreeDiskObject(dobj);
  209.       }
  210.       if (i == 0)
  211.       { /*  Get program's pathname
  212.     */
  213.     if (!NameFromLock(wbarg->wa_Lock, (STRPTR) ProgName,
  214.               sizeof(ProgName)-strlen(wbarg->wa_Name)-1))
  215.     { *ProgName = '\0';
  216.     }
  217.     AddPart((STRPTR) ProgName,
  218.         (STRPTR) wbarg->wa_Name, sizeof(ProgName));
  219.       }
  220.       else
  221.       { args.name = GetStringMem(&key, wbarg->wa_Name);
  222.       }
  223.       if (olddir != -1)
  224.       { CurrentDir(olddir);
  225.       }
  226.     }
  227.   }
  228.   else          /*  CLI program    */
  229.   { struct RDArgs *rdargs;
  230.  
  231.     if ((rdargs = ReadArgs((STRPTR)
  232.                 "FILE,MAKEICONS/S,DEFICON/K,MENUFILE/K,"
  233.                 "LANGUAGE/K,NOWINDOW/S,WINNERPOINTS/K/N,"
  234.                 "DRAWPOINTS/K/N",
  235.                (LONG *) &args, NULL))
  236.         ==  NULL)
  237.     { PrintFault(IoErr(), NULL);
  238.       exit(10);
  239.     }
  240.     if (args.name)
  241.     { args.name = GetStringMem(&key, args.name);
  242.     }
  243.     if (args.language)
  244.     { args.language = GetStringMem(&key, args.language);
  245.     }
  246.     if (args.deficon)
  247.     { args.deficon = GetStringMem(&key, args.deficon);
  248.     }
  249.     if (args.menufile)
  250.     { args.menufile = GetStringMem(&key, args.menufile);
  251.     }
  252.     if (args.winnerpoints)
  253.     { DefaultWinnerPoints = *args.winnerpoints;
  254.     }
  255.     if (args.drawpoints)
  256.     { DefaultDrawPoints = *args.drawpoints;
  257.     }
  258.     FreeArgs(rdargs);
  259.  
  260.     /*    Pfadnamen des Programms bestimmen.
  261.     */
  262.     if (!NameFromLock(((struct Process *) FindTask(NULL))->pr_HomeDir,
  263.               (STRPTR) ProgName,
  264.               sizeof(ProgName)-strlen(argv[0])-1))
  265.     { *ProgName = '\0';
  266.     }
  267.     AddPart((STRPTR) ProgName, (STRPTR) argv[0], sizeof(ProgName));
  268.   }
  269.  
  270.   MakeIcons = args.makeicons;
  271.   NoWindow = args.nowindow;
  272.   if (args.deficon != NULL)
  273.   { MakeIcons = TRUE;
  274.     strcpy(IconName, args.deficon);
  275.   }
  276.   if (args.menufile != NULL)
  277.   { strcpy(MenuName, args.menufile);
  278.   }
  279.  
  280.  
  281.  
  282.   OpenChaosCatalog(NULL, (STRPTR) args.language);
  283.   if (args.name != NULL)
  284.   { LoadTournament(args.name, NULL, NULL);
  285.   }
  286.   PutMemList(&key);
  287. }
  288. #endif    /*  AMIGA   */
  289.  
  290.  
  291.  
  292.  
  293. /*
  294.     This initializes the libraries.
  295. */
  296. void OpenLibs(void)
  297.  
  298. #ifdef AMIGA
  299. { /*  Not all of the above are really needed. Without iffparse.library
  300.       we read the preferences like we did in 1.3 and use the english
  301.       strings on 2.0. Without locale.library we use the english strings
  302.       on 2.1 and above.
  303.   */
  304.   if ((IntuitionBase = OpenLibrary((STRPTR) "intuition.library", 37))
  305.              ==  NULL)
  306.   { ShowError("Cannot open 'intuition.library' V37!");
  307.     exit(10);
  308.   }
  309.   if ((MUIMasterBase = OpenLibrary((STRPTR) "muimaster.library", 5))
  310.              ==  NULL)
  311.   { ShowError("Cannot open 'mui.library' V5 or higher!");
  312.     exit(10);
  313.   }
  314.   if ((UtilityBase = OpenLibrary((STRPTR) "utility.library", 37))  ==  NULL)
  315.   { ShowError("Cannot open 'utility.library' V37!");
  316.     exit(10);
  317.   }
  318.   if ((IconBase = OpenLibrary((STRPTR) "icon.library", 37))  ==  NULL)
  319.   { ShowError("Cannot open 'icon.library' V37!");
  320.     exit(10);
  321.   }
  322.   IFFParseBase = OpenLibrary((STRPTR) "iffparse.library", 37);
  323.   LocaleBase = OpenLibrary((STRPTR) "locale.library", 38);
  324. }
  325. #endif    /*  AMIGA   */
  326.  
  327.  
  328.  
  329. /*
  330.     The InitRandom() function initializes the random number generator.
  331. */
  332. void InitRandom(void)
  333.  
  334. #ifdef AMIGA
  335. { int i;
  336.   struct DateStamp ds;
  337.   extern ULONG RangeSeed;
  338.  
  339.   DateStamp(&ds);
  340.   RangeSeed = ds.ds_Days + ds.ds_Minute + ds.ds_Tick/2;
  341.   for (i = 0;  i < ds.ds_Minute;  i++)
  342.   { RangeRand(ds.ds_Tick);
  343.   }
  344. }
  345. #endif    /*  AMIGA   */
  346.  
  347.  
  348.  
  349. /*
  350.     TerminateWnd() closes the main window.
  351. */
  352. #ifdef AMIGA
  353. APTR App = NULL;                /*  Application object        */
  354. struct DiskObject *AppDiskObject    = NULL;    /*  Icon in iconified state */
  355. #endif    /*  AMIGA   */
  356.  
  357. void TerminateMainWnd(void)
  358.  
  359. #ifdef AMIGA
  360. {
  361.   if (App)
  362.   { MUI_DisposeObject(App);
  363.     App = NULL;
  364.   }
  365.   if (AppDiskObject)
  366.   { FreeDiskObject(AppDiskObject);
  367.   }
  368. }
  369. #endif    /*  AMIGA   */
  370.  
  371.  
  372.  
  373.  
  374. /*
  375.     The InitMainWnd() function brings up the main window. The program is
  376.     terminated, if an error occurs.
  377. */
  378. #ifdef AMIGA
  379. APTR MainWnd;            /*    Main window                */
  380. static APTR TrnFileGad;     /*    Tournament file name            */
  381. static APTR TrnNameGadOut;  /*    Tournament name (output)            */
  382. static APTR TrnModeGad;     /*    Tournament mode             */
  383. static APTR NumPlayersGad;  /*    Number of players            */
  384. static APTR NumRoundsGad;   /*    Number of rounds            */
  385.  
  386.  
  387. #define ID_MenuAction                1
  388. #define ID_Project_New                1001
  389. #define ID_Project_Load             1002
  390. #define ID_Project_Save             1003
  391. #define ID_Project_SaveAs            1004
  392. #define ID_Project_About            1005
  393. #define ID_Project_Quit             1006
  394. #define ID_Players_Add                1007
  395. #define ID_Players_Import            1008
  396. #define ID_Players_Modify            1009
  397. #define ID_Players_Delete            1010
  398. #define ID_Round_Pairings            1011
  399. #define ID_Round_Pairings_SwissPairing        1012
  400. #define ID_Round_Pairings_RoundRobin        1013
  401. #define ID_Round_Pairings_RoundRobinShift   1014
  402. #define ID_Round_Results            1015
  403. #define ID_Round_Results_Sub            1016
  404. #define ID_Output_PlayerList            1017
  405. #define ID_Output_PlayerList_Short        1018
  406. #define ID_Output_PlayerList_Long        1019
  407. #define ID_Output_Rankings            1020
  408. #define ID_Output_Round             1021
  409. #define ID_Output_Round_Sub            1022
  410. #define ID_Output_Table             1023
  411. #define ID_Output_Table_All            1024
  412. #define ID_Output_Table_Seniors         1025
  413. #define ID_Output_Table_Juniors         1026
  414. #define ID_Output_Table_Women            1027
  415. #define ID_Output_Table_JuniorsA        1028
  416. #define ID_Output_Table_JuniorsB        1029
  417. #define ID_Output_Table_JuniorsC        1030
  418. #define ID_Output_Table_JuniorsD        1031
  419. #define ID_Output_Table_JuniorsE        1032
  420. #define ID_Output_TableProgress         1033
  421. #define ID_Output_DWZReport            1034
  422. #define ID_Output_CrossTable            1035
  423. #define ID_Output_CrossTable_Ascii        1036
  424. #define ID_Output_CrossTable_TeX        1037
  425. #define ID_Output_PlayerCards            1038
  426. #define ID_Output_PlayerCards_Ascii        1039
  427. #define ID_Output_PlayerCards_TeX        1040
  428. #define ID_Prefs_Scoring            1041
  429. #define ID_Prefs_Scoring_Simple         1042
  430. #define ID_Prefs_Scoring_Buchholz        1043
  431. #define ID_Prefs_Scoring_ExtBuchholz        1044
  432. #define ID_Prefs_Scoring_SonnebornBerger    1045
  433. #define ID_Prefs_Device             1046
  434. #define ID_Prefs_Device_Screen            1047
  435. #define ID_Prefs_Device_PrinterDraft        1048
  436. #define ID_Prefs_Device_PrinterLQ        1049
  437. #define ID_Prefs_Device_File            1050
  438. #define ID_Prefs_SetGames            1051
  439. #define ID_Prefs_MakeIcons            1052
  440. #endif    /*  Amiga   */
  441.  
  442. void InitMainWnd(void)
  443.  
  444. #ifdef AMIGA
  445. { int open;
  446.   extern void MakeDisplay(void);
  447.   extern struct MUI_Command ARexxCommands[];
  448.  
  449.   static struct NewMenu MainNewMenu[] = {
  450.     NM_TITLE, NULL, NULL, 0, NULL, NULL,
  451.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Project_New,
  452.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Project_Load,
  453.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Project_Save,
  454.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Project_SaveAs,
  455.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Project_About,
  456.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Project_Quit,
  457.     NM_TITLE, NULL, NULL, 0, NULL, NULL,
  458.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Players_Add,
  459.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Players_Import,
  460.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Players_Modify,
  461.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Players_Delete,
  462.     NM_TITLE, NULL, NULL, 0, NULL, NULL,
  463.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Round_Pairings,
  464.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Round_Pairings_SwissPairing,
  465.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Round_Pairings_RoundRobin,
  466.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Round_Pairings_RoundRobinShift,
  467.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Round_Results,
  468.     NM_TITLE, NULL, NULL, 0, NULL, NULL,
  469.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Output_PlayerList,
  470.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_PlayerList_Short,
  471.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_PlayerList_Long,
  472.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Output_Rankings,
  473.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Output_Round,
  474.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Output_Table,
  475.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_Table_All,
  476.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_Table_Seniors,
  477.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_Table_Juniors,
  478.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_Table_Women,
  479.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_Table_JuniorsA,
  480.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_Table_JuniorsB,
  481.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_Table_JuniorsC,
  482.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_Table_JuniorsD,
  483.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_Table_JuniorsE,
  484.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Output_TableProgress,
  485.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Output_DWZReport,
  486.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Output_CrossTable,
  487.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_CrossTable_Ascii,
  488.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_CrossTable_TeX,
  489.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Output_PlayerCards,
  490.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_PlayerCards_Ascii,
  491.     NM_SUB,   NULL, NULL, 0, 0L, (APTR)ID_Output_PlayerCards_TeX,
  492.     NM_TITLE, NULL, NULL, 0, NULL, NULL,
  493.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Prefs_Scoring,
  494.     NM_SUB,   NULL, NULL, CHECKIT|CHECKED, 14L, (APTR)ID_Prefs_Scoring_Simple,
  495.     NM_SUB,   NULL, NULL, CHECKIT, 13L, (APTR)ID_Prefs_Scoring_Buchholz,
  496.     NM_SUB,   NULL, NULL, CHECKIT, 11L, (APTR)ID_Prefs_Scoring_ExtBuchholz,
  497.     NM_SUB,   NULL, NULL, CHECKIT, 7L, (APTR)ID_Prefs_Scoring_SonnebornBerger,
  498.     NM_ITEM,  NULL, NULL, 0, 0L, (APTR)ID_Prefs_Device,
  499.     NM_SUB,   NULL, NULL, CHECKIT|CHECKED, 14L, (APTR)ID_Prefs_Device_Screen,
  500.     NM_SUB,   NULL, NULL, CHECKIT, 13L, (APTR)ID_Prefs_Device_PrinterDraft,
  501.     NM_SUB,   NULL, NULL, CHECKIT, 11L, (APTR)ID_Prefs_Device_PrinterLQ,
  502.     NM_SUB,   NULL, NULL, CHECKIT, 7L, (APTR)ID_Prefs_Device_File,
  503.     NM_ITEM,  NULL, NULL, CHECKIT|MENUTOGGLE, 0L, (APTR)ID_Prefs_SetGames,
  504.     NM_ITEM,  NULL, NULL, CHECKIT|MENUTOGGLE, 0L, (APTR)ID_Prefs_MakeIcons,
  505.     NM_END,   NULL, NULL, 0, 0L, NULL,
  506.     /*
  507.     32 empty entries are following here. The 'special' menu will be
  508.     probably put in here.
  509.     */
  510.     NM_END,   NULL, NULL, 0, 0L, NULL,
  511.     NM_END,   NULL, NULL, 0, 0L, NULL,
  512.     NM_END,   NULL, NULL, 0, 0L, NULL,
  513.     NM_END,   NULL, NULL, 0, 0L, NULL,
  514.     NM_END,   NULL, NULL, 0, 0L, NULL,
  515.     NM_END,   NULL, NULL, 0, 0L, NULL,
  516.     NM_END,   NULL, NULL, 0, 0L, NULL,
  517.     NM_END,   NULL, NULL, 0, 0L, NULL,
  518.     NM_END,   NULL, NULL, 0, 0L, NULL,
  519.     NM_END,   NULL, NULL, 0, 0L, NULL,
  520.     NM_END,   NULL, NULL, 0, 0L, NULL,
  521.     NM_END,   NULL, NULL, 0, 0L, NULL,
  522.     NM_END,   NULL, NULL, 0, 0L, NULL,
  523.     NM_END,   NULL, NULL, 0, 0L, NULL,
  524.     NM_END,   NULL, NULL, 0, 0L, NULL,
  525.     NM_END,   NULL, NULL, 0, 0L, NULL,
  526.     NM_END,   NULL, NULL, 0, 0L, NULL,
  527.     NM_END,   NULL, NULL, 0, 0L, NULL,
  528.     NM_END,   NULL, NULL, 0, 0L, NULL,
  529.     NM_END,   NULL, NULL, 0, 0L, NULL,
  530.     NM_END,   NULL, NULL, 0, 0L, NULL,
  531.     NM_END,   NULL, NULL, 0, 0L, NULL,
  532.     NM_END,   NULL, NULL, 0, 0L, NULL,
  533.     NM_END,   NULL, NULL, 0, 0L, NULL,
  534.     NM_END,   NULL, NULL, 0, 0L, NULL,
  535.     NM_END,   NULL, NULL, 0, 0L, NULL,
  536.     NM_END,   NULL, NULL, 0, 0L, NULL,
  537.     NM_END,   NULL, NULL, 0, 0L, NULL,
  538.     NM_END,   NULL, NULL, 0, 0L, NULL,
  539.     NM_END,   NULL, NULL, 0, 0L, NULL,
  540.     NM_END,   NULL, NULL, 0, 0L, NULL,
  541.     NM_END,   NULL, NULL, 0, 0L, NULL
  542.   };
  543.  
  544.   /*
  545.       Initializing the menu-strings. (Localizing)
  546.   */
  547.   MainNewMenu[0].nm_Label = GetChaosString(MSG_TOURNAMENT_MENU);
  548.   MainNewMenu[1].nm_Label = GetChaosString(MSG_TOURNAMENT_NEW_ITEM);
  549.   MainNewMenu[2].nm_Label = GetChaosString(MSG_TOURNAMENT_LOAD_ITEM);
  550.   MainNewMenu[2].nm_CommKey = GetChaosString(KEY_PROJECT_LOAD);
  551.   MainNewMenu[3].nm_Label = GetChaosString(MSG_TOURNAMENT_SAVE_ITEM);
  552.   MainNewMenu[3].nm_CommKey = GetChaosString(KEY_PROJECT_SAVE);
  553.   MainNewMenu[4].nm_Label = GetChaosString(MSG_TOURNAMENT_SAVEAS_ITEM);
  554.   MainNewMenu[4].nm_CommKey = GetChaosString(KEY_PROJECT_SAVE_AS);
  555.   MainNewMenu[5].nm_Label = GetChaosString(MSG_TOURNAMENT_ABOUT_ITEM);
  556.   MainNewMenu[5].nm_CommKey = GetChaosString(KEY_PROJECT_ABOUT);
  557.   MainNewMenu[6].nm_Label = GetChaosString(MSG_TOURNAMENT_QUIT_ITEM);
  558.   MainNewMenu[7].nm_Label = GetChaosString(MSG_PLAYER_MENU);
  559.   MainNewMenu[8].nm_Label = GetChaosString(MSG_PLAYER_ADD_ITEM);
  560.   MainNewMenu[8].nm_CommKey = GetChaosString(KEY_PLAYERS_NEW);
  561.   MainNewMenu[9].nm_Label = GetChaosString(MSG_PLAYER_IMPORT_ITEM);
  562.   MainNewMenu[10].nm_Label = GetChaosString(MSG_PLAYER_MODIFY_ITEM);
  563.   MainNewMenu[10].nm_CommKey = GetChaosString(KEY_PLAYERS_MODIFY);
  564.   MainNewMenu[11].nm_Label = GetChaosString(MSG_PLAYER_DELETE_ITEM);
  565.   MainNewMenu[12].nm_Label = GetChaosString(MSG_ROUND_MENU);
  566.   MainNewMenu[13].nm_Label = GetChaosString(MSG_ROUND_PAIRINGS_ITEM);
  567.   MainNewMenu[14].nm_Label = GetChaosString(MSG_ROUND_PAIRINGS_SWISS_SUB);
  568.   MainNewMenu[15].nm_Label = GetChaosString(MSG_ROUND_PAIRINGS_RROBIN_SUB);
  569.   MainNewMenu[16].nm_Label = GetChaosString(MSG_ROUND_PAIRINGS_SLIDE_SUB);
  570.   MainNewMenu[17].nm_Label = GetChaosString(MSG_ROUND_RESULTS_ITEM);
  571.   MainNewMenu[18].nm_Label = GetChaosString(MSG_OUTPUT_MENU);
  572.   MainNewMenu[19].nm_Label = GetChaosString(MSG_OUTPUT_PLAYERS_ITEM);
  573.   MainNewMenu[20].nm_Label = GetChaosString(MSG_OUTPUT_PLAYERS_SHORT_SUB);
  574.   MainNewMenu[21].nm_Label = GetChaosString(MSG_OUTPUT_PLAYERS_LONG_SUB);
  575.   MainNewMenu[22].nm_Label = GetChaosString(MSG_OUTPUT_RANKINGS_ITEM);
  576.   MainNewMenu[23].nm_Label = GetChaosString(MSG_OUTPUT_ROUND_ITEM);
  577.   MainNewMenu[24].nm_Label = GetChaosString(MSG_OUTPUT_TABLE_ITEM);
  578.   MainNewMenu[25].nm_Label = GetChaosString(MSG_OUTPUT_TABLE_ALL_SUB);
  579.   MainNewMenu[26].nm_Label = GetChaosString(MSG_OUTPUT_TABLE_SENIORS_SUB);
  580.   MainNewMenu[27].nm_Label = GetChaosString(MSG_OUTPUT_TABLE_JUNIORS_SUB);
  581.   MainNewMenu[28].nm_Label = GetChaosString(MSG_OUTPUT_TABLE_WOMEN_SUB);
  582.   MainNewMenu[29].nm_Label = GetChaosString(MSG_OUTPUT_TABLE_JUNIORSA_SUB);
  583.   MainNewMenu[30].nm_Label = GetChaosString(MSG_OUTPUT_TABLE_JUNIORSB_SUB);
  584.   MainNewMenu[31].nm_Label = GetChaosString(MSG_OUTPUT_TABLE_JUNIORSC_SUB);
  585.   MainNewMenu[32].nm_Label = GetChaosString(MSG_OUTPUT_TABLE_JUNIORSD_SUB);
  586.   MainNewMenu[33].nm_Label = GetChaosString(MSG_OUTPUT_TABLE_JUNIORSE_SUB);
  587.   MainNewMenu[34].nm_Label = GetChaosString(MSG_OUTPUT_PROGRESSTABLE_ITEM);
  588.   MainNewMenu[35].nm_Label = GetChaosString(MSG_OUTPUT_DWZ_ITEM);
  589.   MainNewMenu[36].nm_Label = GetChaosString(MSG_OUTPUT_CROSSTABLE_ITEM);
  590.   MainNewMenu[37].nm_Label = GetChaosString(MSG_OUTPUT_CROSSTABLE_ASC_SUB);
  591.   MainNewMenu[38].nm_Label = GetChaosString(MSG_OUTPUT_CROSSTABLE_TEX_SUB);
  592.   MainNewMenu[39].nm_Label = GetChaosString(MSG_OUTPUT_PLAYERCARDS_ITEM);
  593.   MainNewMenu[40].nm_Label = GetChaosString(MSG_OUTPUT_PLAYERCARDS_ASC_SUB);
  594.   MainNewMenu[41].nm_Label = GetChaosString(MSG_OUTPUT_PLAYERCARDS_TEX_SUB);
  595.   MainNewMenu[42].nm_Label = GetChaosString(MSG_PREFS_MENU);
  596.   MainNewMenu[43].nm_Label = GetChaosString(MSG_PREFS_TMODE_ITEM);
  597.   MainNewMenu[44].nm_Label = GetChaosString(MSG_PREFS_TMODE_SIMPLE_SUB);
  598.   MainNewMenu[45].nm_Label = GetChaosString(MSG_PREFS_TMODE_BUCHHOLZ_SUB);
  599.   MainNewMenu[46].nm_Label = GetChaosString(MSG_PREFS_TMODE_EXTBCHHLZ_SUB);
  600.   MainNewMenu[47].nm_Label = GetChaosString(MSG_PREFS_TMODE_SONNEBORN_SUB);
  601.   MainNewMenu[48].nm_Label = GetChaosString(MSG_PREFS_OUT_ITEM);
  602.   MainNewMenu[49].nm_Label = GetChaosString(MSG_PREFS_OUT_SCREEN_SUB);
  603.   MainNewMenu[50].nm_Label = GetChaosString(MSG_PREFS_OUT_PRTDRAFT_SUB);
  604.   MainNewMenu[51].nm_Label = GetChaosString(MSG_PREFS_OUT_PRTLQ_SUB);
  605.   MainNewMenu[52].nm_Label = GetChaosString(MSG_PREFS_OUT_FILE_SUB);
  606.   MainNewMenu[53].nm_Label = GetChaosString(MSG_PREFS_SETGAMES);
  607.   MainNewMenu[54].nm_Label = GetChaosString(MSG_PREFS_MAKEICONS_ITEM);
  608.  
  609.   /*
  610.       Reading the menu file.
  611.   */
  612.   { FILE *fh;
  613.  
  614.     if ((fh = fopen(MenuName, "r"))  !=  NULL  ||
  615.     (fh = fopen("s:Chaos_Menu", "r"))  !=  NULL)
  616.     { int size;
  617.       char *menufile;
  618.  
  619.       fseek(fh, 0, SEEK_END);
  620.       size = ftell(fh);
  621.       if ((menufile = malloc(size+1))  ==  NULL)
  622.       { ShowError("Cannot read menufile, ignoring.");
  623.       }
  624.       else
  625.       { fseek(fh, 0, SEEK_SET);
  626.     if (fread(menufile, size, 1, fh)  !=  1)
  627.     { ShowError("Cannot read menufile, ignoring.");
  628.     }
  629.     else
  630.     { int NumLines = 0;
  631.       struct NewMenu *nm = MainNewMenu;
  632.  
  633.       /*
  634.           Look, where to put in the special menu.
  635.       */
  636.       while (nm->nm_Type != NM_END)
  637.       { nm++;
  638.       }
  639.  
  640.       /*
  641.           Creating the menu header
  642.       */
  643.       nm->nm_Type = NM_TITLE;
  644.       nm->nm_Label = GetChaosString(MSG_SPECIAL_MENU);
  645.  
  646.       /*
  647.           Scanning the menu file
  648.       */
  649.       menufile[size] = '\0';
  650.       while(*menufile != 0  &&  NumLines < 31)
  651.       { ++nm;
  652.         ++NumLines;
  653.         nm->nm_Type = NM_ITEM;
  654.         nm->nm_Label = (STRPTR) menufile;
  655.         while(*menufile != '\n'  &&  *menufile != '\0')
  656.         { ++menufile;
  657.         }
  658.         if (*menufile != '\0')
  659.         { *menufile = '\0';
  660.           nm->nm_UserData = (APTR) ++menufile;
  661.           while(*menufile != '\n'  &&  *menufile != '\0')
  662.           { ++menufile;
  663.           }
  664.           if (*menufile != '\0')
  665.           { *(menufile++) = '\0';
  666.           }
  667.         }
  668.       }
  669.     }
  670.       }
  671.       fclose(fh);
  672.     }
  673.   }
  674.  
  675.   /*
  676.       Get the programs icon to show it in iconified state.
  677.   */
  678.   AppDiskObject = GetDiskObject((STRPTR) ProgName);
  679.  
  680.   /*
  681.       Creating the GUI
  682.   */
  683.   App = ApplicationObject,
  684.         MUIA_Application_Title,        "Chaos",
  685.         MUIA_Application_Version,        VERVERSION,
  686.         MUIA_Application_Copyright,     "© 1993, Jochen Wiedmann",
  687.         MUIA_Application_Author,        "Jochen Wiedmann",
  688.         MUIA_Application_Description,   "The Chess HAppening Organisation System",
  689.         MUIA_Application_Base,        "CHAOS",
  690.         MUIA_Application_Commands,        ARexxCommands,
  691.         AppDiskObject ? MUIA_Application_DiskObject : TAG_IGNORE,
  692.                         AppDiskObject,
  693.         SubWindow, MainWnd = WindowObject,
  694.         MUIA_Window_ID, MAKE_ID('M','A','I','N'),
  695.         MUIA_Window_Title, AVERSION,
  696.         MUIA_Window_Menu, MainNewMenu,
  697.         WindowContents, VGroup,
  698.             Child, TextObject,
  699.             GroupFrame,
  700.             MUIA_Background, MUII_FILLBACK2,
  701.             MUIA_Text_Contents, "\033cC h a o s\n"
  702.                         "\033cThe Chess HAppening Organisation System\n"
  703.                         "Copyright © 1993,      Jochen Wiedmann",
  704.             End,
  705.             Child, ColGroup(2),
  706.             Child, Label2(GetChaosString(MSG_TOURNAMENT_FILE_OUTPUT)),
  707.             Child, TrnFileGad = TextObject,
  708.             End,
  709.             Child, Label2(GetChaosString(MSG_TOURNAMENT_NAME_OUTPUT)),
  710.             Child, TrnNameGadOut = TextObject,
  711.             End,
  712.             Child, Label2(GetChaosString(MSG_TOURNAMENT_MODE_OUTPUT)),
  713.             Child, TrnModeGad = TextObject,
  714.             End,
  715.             End,
  716.             Child, HGroup,
  717.             Child, Label2(GetChaosString(MSG_NUM_PLAYERS_OUTPUT)),
  718.             Child, NumPlayersGad = TextObject,
  719.             End,
  720.             Child, HSpace(0),
  721.             Child, Label2(GetChaosString(MSG_NUM_ROUNDS_OUTPUT)),
  722.             Child, NumRoundsGad = TextObject,
  723.             Child, HSpace(0),
  724.             End,
  725.             End,
  726.         End,
  727.         End,
  728.     End;
  729.  
  730.   /*
  731.       Successfull?
  732.   */
  733.   if (App == NULL)
  734.   { ShowError(GetChaosString(MSG_MEMORY_ERROR));
  735.     exit(10);
  736.   }
  737.  
  738.   /*
  739.       Setting up the notification events for the main window
  740.   */
  741.   DoMethod(MainWnd, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, App, 2,
  742.        MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  743.   DoMethod(App, MUIM_Notify, MUIA_Application_MenuAction, MUIV_EveryTime,
  744.        App, 2, MUIM_Application_ReturnID, ID_MenuAction);
  745.  
  746.  
  747.  
  748.   /*
  749.       Opening the main window and checking for success
  750.   */
  751.   if (!NoWindow)
  752.   { set (MainWnd, MUIA_Window_Open, TRUE);
  753.     MakeDisplay();
  754.     get (MainWnd, MUIA_Window_Open, &open);
  755.     if (!open)
  756.     { MUIError((char *) GetChaosString(ERRMSG_CANNOT_OPEN_WINDOW));
  757.       TerminateMainWnd();
  758.     }
  759.   }
  760. }
  761. #endif    /*  AMIGA   */
  762.  
  763.  
  764.  
  765.  
  766. /*
  767.     The ShowError() function should bring up a requester telling an error.
  768. */
  769. void ShowError(char *msg, ...)
  770.  
  771. #ifdef AMIGA
  772. {
  773.   if (App)
  774.   { MUI_RequestA(App, MainWnd, 0, (char *) GetChaosString(MSG_ERROR_REQUEST),
  775.            (char *) GetChaosString(MSG_OK), msg, (&msg)+1);
  776.   }
  777.   else if (IntuitionBase)
  778.   { struct EasyStruct es;
  779.  
  780.     es.es_StructSize = sizeof(es);
  781.     es.es_Flags = 0;
  782.     es.es_Title = GetChaosString(MSG_ERROR_REQUEST);
  783.     es.es_TextFormat = (STRPTR) msg;
  784.     es.es_GadgetFormat = GetChaosString(MSG_OK);
  785.     EasyRequestArgs(NULL, &es, NULL, (&msg)+1);
  786.   }
  787.   else if (AllowErrorMessage)
  788.   { printf("%s\n", msg);
  789.   }
  790. }
  791. #endif    /*  AMIGA   */
  792.  
  793.  
  794.  
  795. #ifdef AMIGA
  796. /*
  797.     The following function gets called, if an MUI command fails.
  798.  
  799. */
  800. void MUIError(char *msg)
  801. { char *errmsg;
  802.  
  803.   switch (MUI_Error())
  804.   { case MUIE_OK:
  805.       errmsg = (char *) GetChaosString(MUIERR_OK);
  806.       break;
  807.     case MUIE_OutOfMemory:
  808.       errmsg = (char *) GetChaosString(MUIERR_OutOfMemory);
  809.       break;
  810.     case MUIE_OutOfGfxMemory:
  811.       errmsg = (char *) GetChaosString(MUIERR_OutOfGfxMemory);
  812.       break;
  813.     case MUIE_InvalidWindowObject:
  814.       errmsg = (char *) GetChaosString(MUIERR_InvalidWindowObject);
  815.       break;
  816.     case MUIE_MissingLibrary:
  817.       errmsg = (char *) GetChaosString(MUIERR_MissingLibrary);
  818.       break;
  819.     case MUIE_NoARexx:
  820.       errmsg = (char *) GetChaosString(MUIERR_NoARexx);
  821.       break;
  822.     case MUIE_SingleTask:
  823.       errmsg = (char *) GetChaosString(MUIERR_SingleTask);
  824.       break;
  825.     default:
  826.       errmsg = (char *) GetChaosString(MUIERR_Unknown);
  827.   }
  828.  
  829.   ShowError(msg, errmsg);
  830. }
  831. #endif    /*  AMIGA   */
  832.  
  833.  
  834.  
  835.  
  836. /*
  837.     MemError() gets called, when memory is missing.
  838. */
  839. void MemError(void)
  840.  
  841. { ShowError((char *) GetChaosString(MSG_MEMORY_ERROR));
  842. }
  843.  
  844.  
  845.  
  846.  
  847. /*
  848.     MakeDisplay() refreshs the information gadgets, enables or disables the
  849.     menuitems and looks for the menu preferences.
  850. */
  851. void MakeDisplay(void)
  852.  
  853. #ifdef AMIGA
  854. { char numrounds[10], numplayers[10];
  855.  
  856.   /*
  857.       Information gadgets
  858.   */
  859.   set(TrnFileGad, MUIA_Text_Contents, TrnFileName);
  860.   set (TrnNameGadOut, MUIA_Text_Contents, TrnName);
  861.   switch (TrnMode &
  862.       (TNMODEF_SWISS_PAIRING|TNMODEF_ROUND_ROBIN|TNMODEF_SHIFT_SYSTEM))
  863.   { case 0:
  864.       set(TrnModeGad, MUIA_Text_Contents, NULL);
  865.       break;
  866.     case TNMODEF_SWISS_PAIRING:
  867.       set(TrnModeGad, MUIA_Text_Contents, GetChaosString(MSG_SWISS_PAIRING));
  868.       break;
  869.     case TNMODEF_ROUND_ROBIN:
  870.       set(TrnModeGad, MUIA_Text_Contents, GetChaosString(MSG_RUNDENTURNIER));
  871.       break;
  872.     default:
  873.       set(TrnModeGad, MUIA_Text_Contents, GetChaosString(MSG_RUTSCHSYSTEM));
  874.       break;
  875.   }
  876.   sprintf(numrounds, "%d", NumRounds);
  877.   set(NumRoundsGad, MUIA_Text_Contents, numrounds);
  878.   sprintf(numplayers, "%d", NumPlayers);
  879.   set(NumPlayersGad, MUIA_Text_Contents, numplayers);
  880.  
  881.  
  882.   /*
  883.       Enabling and disabling menu items
  884.   */
  885. #define SetMenu(id, flag) \
  886.     DoMethod(MainWnd, MUIM_Window_SetMenuState, (id), (flag))
  887.  
  888.   SetMenu(ID_Players_Add,
  889.       !((RoundRobinTournament  &&  NumRounds > 0)  ||
  890.       (SwissPairingTournament  &&  NumRounds > 1)));
  891.   SetMenu(ID_Players_Import,
  892.       !((RoundRobinTournament  &&  NumRounds > 0)  ||
  893.       (SwissPairingTournament  &&  NumRounds > 1)));
  894.   SetMenu(ID_Players_Modify, NumPlayers > 0);
  895.   SetMenu(ID_Players_Delete,
  896.       (NumRounds == 0  &&  NumPlayers > 0)  || SwissPairingTournament);
  897.  
  898.   SetMenu(ID_Round_Pairings,
  899.       (NumRounds == 0  &&  NumPlayers > 0)  || SwissPairingTournament);
  900.   SetMenu(ID_Round_Pairings_SwissPairing,
  901.       (NumRounds == 0  &&  NumPlayers > 0)  ||
  902.       (SwissPairingTournament  &&  NumGamesMissing == 0));
  903.   SetMenu(ID_Round_Pairings_RoundRobin, NumRounds == 0  &&  NumPlayers > 0);
  904.   SetMenu(ID_Round_Pairings_RoundRobinShift,
  905.       NumRounds == 0  &&  NumPlayers > 0);
  906.   SetMenu(ID_Round_Results, NumRounds > 0);
  907.  
  908.   SetMenu(ID_Output_PlayerList, NumPlayers > 0);
  909.   SetMenu(ID_Output_Rankings, NumPlayers > 0);
  910.   SetMenu(ID_Output_Round, NumRounds > 0);
  911.   SetMenu(ID_Output_Table, NumRounds > 0);
  912.   SetMenu(ID_Output_TableProgress, SwissPairingTournament);
  913.   SetMenu(ID_Output_CrossTable, RoundRobinTournament);
  914.   SetMenu(ID_Output_PlayerCards,
  915.       (NumPlayers > 0  &&  NumRounds == 0)  ||  SwissPairingTournament);
  916.   SetMenu(ID_Output_DWZReport, NumRounds > 0);
  917.  
  918.   SetMenu(ID_Prefs_Scoring, NumRounds > 0);
  919.   SetMenu(ID_Prefs_Scoring_Buchholz, SwissPairingTournament);
  920.   SetMenu(ID_Prefs_Scoring_ExtBuchholz, SwissPairingTournament);
  921.   SetMenu(ID_Prefs_Scoring_SonnebornBerger, RoundRobinTournament);
  922.  
  923.   /*
  924.       Finally let the items of the preferences menu reflect the current
  925.       settings
  926.   */
  927. #define SetMenuCheck(id, flag) \
  928.     DoMethod(MainWnd, MUIM_Window_SetMenuCheck, (id), (flag))
  929.  
  930.   switch(TrnMode & TNMODE_TABMASK)
  931.   { case 0:
  932.       SetMenuCheck(ID_Prefs_Scoring_Simple, TRUE);
  933.       SetMenuCheck(ID_Prefs_Scoring_Buchholz, FALSE);
  934.       SetMenuCheck(ID_Prefs_Scoring_ExtBuchholz, FALSE);
  935.       SetMenuCheck(ID_Prefs_Scoring_SonnebornBerger, FALSE);
  936.       break;
  937.     case TNMODEF_BUCHHOLZ:
  938.       SetMenuCheck(ID_Prefs_Scoring_Simple, FALSE);
  939.       SetMenuCheck(ID_Prefs_Scoring_Buchholz, TRUE);
  940.       SetMenuCheck(ID_Prefs_Scoring_ExtBuchholz, FALSE);
  941.       SetMenuCheck(ID_Prefs_Scoring_SonnebornBerger, FALSE);
  942.       break;
  943.     case TNMODEF_EXT_BUCHHOLZ:
  944.       SetMenuCheck(ID_Prefs_Scoring_Simple, FALSE);
  945.       SetMenuCheck(ID_Prefs_Scoring_Buchholz, FALSE);
  946.       SetMenuCheck(ID_Prefs_Scoring_ExtBuchholz, TRUE);
  947.       SetMenuCheck(ID_Prefs_Scoring_SonnebornBerger, FALSE);
  948.       break;
  949.     case TNMODEF_SONNEBORN_BERGER:
  950.       SetMenuCheck(ID_Prefs_Scoring_Simple, FALSE);
  951.       SetMenuCheck(ID_Prefs_Scoring_Buchholz, FALSE);
  952.       SetMenuCheck(ID_Prefs_Scoring_ExtBuchholz, FALSE);
  953.       SetMenuCheck(ID_Prefs_Scoring_SonnebornBerger, TRUE);
  954.       break;
  955.   }
  956.   switch (OutputDevice)
  957.   { case DEVICE_Screen:
  958.       SetMenuCheck(ID_Prefs_Device_Screen, TRUE);
  959.       SetMenuCheck(ID_Prefs_Device_PrinterDraft, FALSE);
  960.       SetMenuCheck(ID_Prefs_Device_PrinterLQ, FALSE);
  961.       SetMenuCheck(ID_Prefs_Device_File, FALSE);
  962.       break;
  963.     case DEVICE_PrinterDraft:
  964.       SetMenuCheck(ID_Prefs_Device_Screen, FALSE);
  965.       SetMenuCheck(ID_Prefs_Device_PrinterDraft, TRUE);
  966.       SetMenuCheck(ID_Prefs_Device_PrinterLQ, FALSE);
  967.       SetMenuCheck(ID_Prefs_Device_File, FALSE);
  968.       break;
  969.     case DEVICE_PrinterLQ:
  970.       SetMenuCheck(ID_Prefs_Device_Screen, FALSE);
  971.       SetMenuCheck(ID_Prefs_Device_PrinterDraft, FALSE);
  972.       SetMenuCheck(ID_Prefs_Device_PrinterLQ, TRUE);
  973.       SetMenuCheck(ID_Prefs_Device_File, FALSE);
  974.       break;
  975.     case DEVICE_FileAscii:
  976.       SetMenuCheck(ID_Prefs_Device_Screen, FALSE);
  977.       SetMenuCheck(ID_Prefs_Device_PrinterDraft, FALSE);
  978.       SetMenuCheck(ID_Prefs_Device_PrinterLQ, FALSE);
  979.       SetMenuCheck(ID_Prefs_Device_File, TRUE);
  980.       break;
  981.   }
  982.   SetMenuCheck(ID_Prefs_MakeIcons, MakeIcons);
  983. }
  984. #endif    /*  AMIGA   */
  985.  
  986.  
  987.  
  988.  
  989. /*
  990.     ProcessMainWnd() waits for user actions like selecting a menu or
  991.     messages from the ARexx-port and processes them in an endless loop.
  992. */
  993. int EnableARexx = TRUE;
  994. static int GamesToBeSet = FALSE;
  995. void ProcessMainWnd(void)
  996.  
  997. #ifdef AMIGA
  998. { ULONG Signal, open, ID;
  999.   APTR UserData;
  1000.   int round;
  1001.  
  1002.   for (;;)
  1003.   { /*
  1004.     Disable the menus, so the window is sleeping for our purposes.
  1005.     */
  1006.     set (MainWnd, MUIA_Window_NoMenus, TRUE);
  1007.  
  1008.     /*
  1009.     Check for user actions
  1010.     */
  1011.     ID = DoMethod(App, MUIM_Application_Input, &Signal);
  1012.     EnableARexx = FALSE;
  1013.     switch(ID)
  1014.     { case MUIV_Application_ReturnID_Quit:
  1015.     if (TestSaved())
  1016.     { exit(0);
  1017.     }
  1018.     break;
  1019.       case ID_MenuAction:
  1020.     get(App, MUIA_Application_MenuAction, &UserData);
  1021.     switch((ULONG) UserData)
  1022.     { case ID_Project_Quit:
  1023.         if (TestSaved())
  1024.         { exit(0);
  1025.         }
  1026.         break;
  1027.       case ID_Project_New:
  1028.         if (TestSaved())
  1029.         { NewTournament();
  1030.         }
  1031.         break;
  1032.       case ID_Project_Load:
  1033.         if (TestSaved())
  1034.         { LoadTournament(NULL, NULL, NULL);
  1035.         }
  1036.         break;
  1037.       case ID_Project_Save:
  1038.         SaveTournament(TrnFileName);
  1039.         break;
  1040.       case ID_Project_SaveAs:
  1041.         SaveTournament(NULL);
  1042.         break;
  1043.       case ID_Project_About:
  1044.         About();
  1045.         break;
  1046.       case ID_Players_Add:
  1047.         AddPlayers();
  1048.         break;
  1049.       case ID_Players_Import:
  1050.         ImportPlayers();
  1051.         break;
  1052.       case ID_Players_Modify:
  1053.         ModifyPlayers();
  1054.         break;
  1055.       case ID_Players_Delete:
  1056.         DeletePlayers();
  1057.         break;
  1058.       case ID_Round_Pairings_SwissPairing:
  1059.         DoPairings(TNMODEF_SWISS_PAIRING, TRUE, GamesToBeSet);
  1060.         break;
  1061.       case ID_Round_Pairings_RoundRobin:
  1062.         DoPairings(TNMODEF_ROUND_ROBIN, TRUE, FALSE);
  1063.         break;
  1064.       case ID_Round_Pairings_RoundRobinShift:
  1065.         DoPairings(TNMODEF_ROUND_ROBIN | TNMODEF_SHIFT_SYSTEM, TRUE, FALSE);
  1066.         break;
  1067.       case ID_Round_Results:
  1068.         if ((round = GetRoundNr()) != 0)
  1069.         { EnterResults(round);
  1070.         }
  1071.         break;
  1072.       case ID_Output_PlayerList_Short:
  1073.         OutPlayerList(NULL, OutputDevice, FALSE);
  1074.         break;
  1075.       case ID_Output_PlayerList_Long:
  1076.         OutPlayerList(NULL, OutputDevice, TRUE);
  1077.         break;
  1078.       case ID_Output_Rankings:
  1079.         OutInternalRankings(NULL, OutputDevice);
  1080.         break;
  1081.       case ID_Output_Round:
  1082.         if ((round = GetRoundNr()) != 0)
  1083.         { OutRound(NULL, OutputDevice, round);
  1084.         }
  1085.         break;
  1086.       case ID_Output_Table_All:
  1087.         OutTable(NULL, OutputDevice, 0, TrnMode);
  1088.         break;
  1089.       case ID_Output_Table_Seniors:
  1090.         OutTable(NULL, OutputDevice, TNFLAGSF_SENIOR, TrnMode);
  1091.         break;
  1092.       case ID_Output_Table_Juniors:
  1093.         OutTable(NULL, OutputDevice, TNFLAGSF_JUNIOR, TrnMode);
  1094.         break;
  1095.       case ID_Output_Table_Women:
  1096.         OutTable(NULL, OutputDevice, TNFLAGSF_WOMAN, TrnMode);
  1097.         break;
  1098.       case ID_Output_Table_JuniorsA:
  1099.         OutTable(NULL, OutputDevice, TNFLAGSF_JUNIORA, TrnMode);
  1100.         break;
  1101.       case ID_Output_Table_JuniorsB:
  1102.         OutTable(NULL, OutputDevice, TNFLAGSF_JUNIORB, TrnMode);
  1103.         break;
  1104.       case ID_Output_Table_JuniorsC:
  1105.         OutTable(NULL, OutputDevice, TNFLAGSF_JUNIORC, TrnMode);
  1106.         break;
  1107.       case ID_Output_Table_JuniorsD:
  1108.         OutTable(NULL, OutputDevice, TNFLAGSF_JUNIORD, TrnMode);
  1109.         break;
  1110.       case ID_Output_Table_JuniorsE:
  1111.         OutTable(NULL, OutputDevice, TNFLAGSF_JUNIORE, TrnMode);
  1112.         break;
  1113.       case ID_Output_TableProgress:
  1114.         OutTableProgress(NULL, OutputDevice, TrnMode);
  1115.         break;
  1116.       case ID_Output_DWZReport:
  1117.         OutDWZReport(NULL, OutputDevice);
  1118.         break;
  1119.       case ID_Output_CrossTable_Ascii:
  1120.         OutCrossTable(NULL, OutputDevice);
  1121.         break;
  1122.       case ID_Output_CrossTable_TeX:
  1123.         OutCrossTable(NULL, DEVICE_FileTeX);
  1124.         break;
  1125.       case ID_Output_PlayerCards_Ascii:
  1126.         OutPlayerCards(NULL, OutputDevice);
  1127.         break;
  1128.       case ID_Output_PlayerCards_TeX:
  1129.         OutPlayerCards(NULL, DEVICE_FileTeX);
  1130.         break;
  1131.       case ID_Prefs_Scoring_Simple:
  1132.         TrnMode &= ~TNMODE_TABMASK;
  1133.         break;
  1134.       case ID_Prefs_Scoring_Buchholz:
  1135.         TrnMode = (TrnMode & ~TNMODE_TABMASK) | TNMODEF_BUCHHOLZ;
  1136.         break;
  1137.       case ID_Prefs_Scoring_ExtBuchholz:
  1138.         TrnMode = (TrnMode & ~TNMODE_TABMASK) | TNMODEF_EXT_BUCHHOLZ;
  1139.         break;
  1140.       case ID_Prefs_Scoring_SonnebornBerger:
  1141.         TrnMode = (TrnMode & ~TNMODE_TABMASK) | TNMODEF_SONNEBORN_BERGER;
  1142.         break;
  1143.       case ID_Prefs_Device_Screen:
  1144.         OutputDevice = DEVICE_Screen;
  1145.         break;
  1146.       case ID_Prefs_Device_PrinterDraft:
  1147.         OutputDevice = DEVICE_PrinterDraft;
  1148.         break;
  1149.       case ID_Prefs_Device_PrinterLQ:
  1150.         OutputDevice = DEVICE_PrinterLQ;
  1151.         break;
  1152.       case ID_Prefs_Device_File:
  1153.         OutputDevice = DEVICE_FileAscii;
  1154.         break;
  1155.       case ID_Prefs_SetGames:
  1156.         GamesToBeSet = !GamesToBeSet;
  1157.         break;
  1158.       case ID_Prefs_MakeIcons:
  1159.         MakeIcons = !MakeIcons;
  1160.         break;
  1161.       default:
  1162.         if (UserData != NULL)
  1163.         { EnableARexx = TRUE;
  1164.           SystemTags(UserData, SYS_UserShell, NULL, TAG_END);
  1165.         }
  1166.     }
  1167.     }
  1168.     EnableARexx = TRUE;
  1169.  
  1170.     /*
  1171.     Let the window awake.
  1172.     */
  1173.     get(MainWnd, MUIA_Window_Open, &open);
  1174.     if (!NoWindow)
  1175.     { if (!open)
  1176.       { set(MainWnd, MUIA_Window_Open, TRUE);
  1177.       }
  1178.       MakeDisplay();
  1179.       set(MainWnd, MUIA_Window_NoMenus, FALSE);
  1180.     }
  1181.     EnableARexx = TRUE;
  1182.  
  1183.  
  1184.     /*
  1185.     And put the application to sleep, waiting for user actions.
  1186.     */
  1187.     if(Signal)
  1188.     { Wait(Signal);
  1189.     }
  1190.   }
  1191. }
  1192. #endif    /*  AMIGA   */
  1193.  
  1194.  
  1195.  
  1196.  
  1197. /*
  1198.     SetupPrefs() sets up the preferences in a way corresponding to a new
  1199.     or loaded tournament.
  1200. */
  1201. void SetupPrefs(void)
  1202. #ifdef AMIGA
  1203. { switch (TrnMode &= TNMODE_TABMASK)
  1204.   { case TNMODEF_BUCHHOLZ:
  1205.       DoMethod(MainWnd, MUIM_Window_SetMenuCheck, ID_Prefs_Scoring_Buchholz,
  1206.            TRUE);
  1207.       break;
  1208.     case TNMODEF_EXT_BUCHHOLZ:
  1209.       DoMethod(MainWnd, MUIM_Window_SetMenuCheck,
  1210.            ID_Prefs_Scoring_ExtBuchholz, TRUE);
  1211.       break;
  1212.     case TNMODEF_SONNEBORN_BERGER:
  1213.       DoMethod(MainWnd, MUIM_Window_SetMenuCheck,
  1214.            ID_Prefs_Scoring_SonnebornBerger, TRUE);
  1215.       break;
  1216.     default:
  1217.       DoMethod(MainWnd, MUIM_Window_SetMenuCheck, ID_Prefs_Scoring_Simple,
  1218.            TRUE);
  1219.       break;
  1220.   }
  1221. }
  1222. #endif    /*  AMIGA   */
  1223.